package com.zx.kitchen.index.common.mvp.presenter;

import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.zx.kitchen.index.common.entity.GoodReportGetDishesByFidBean;
import com.zx.kitchen.index.common.mvp.OnResultListener;
import com.zx.kitchen.index.common.mvp.model.PurchaseGoodsReportGetDishesByFidModelImpl;
import com.zx.kitchen.index.common.mvp.view.GoodsReportGetDishesByFidView;

/**
 * Created by Administrator on 2017/3/20.
 */

public class PurchaseGoodsReportGetDishesByFidPresenter implements OnResultListener {
    private PurchaseGoodsReportGetDishesByFidModelImpl purchaseGoodsReportGetDishesByFidModel;
    private GoodsReportGetDishesByFidView goodsReportGetDishesByFidView;
    private Context context;

    public PurchaseGoodsReportGetDishesByFidPresenter(GoodsReportGetDishesByFidView goodsReportGetDishesByFidView, Context context) {
        this.goodsReportGetDishesByFidView = goodsReportGetDishesByFidView;
        this.context = context;
        purchaseGoodsReportGetDishesByFidModel = new PurchaseGoodsReportGetDishesByFidModelImpl();
    }

    public void getFromNet(String fid, int is_last) {
        purchaseGoodsReportGetDishesByFidModel.getFromNet(0, context, fid, is_last, this, null);
    }


    @Override
    public void onSuccess(int requestCode, String str) {
        GoodReportGetDishesByFidBean goodReportGetDishesByFidBean = JSON.parseObject(str, new TypeReference<GoodReportGetDishesByFidBean>() {
        });
        goodsReportGetDishesByFidView.onSuccess(goodReportGetDishesByFidBean);
    }

    @Override
    public void onFailure(int requestCode, String str) {
        goodsReportGetDishesByFidView.onFail(str);
    }
}
